package com.synnex.mobile.servier.core.contact.service.impl;

import com.synnex.mobile.generic.core.util.ObjectUtil;
import com.synnex.mobile.servier.core.contact.bo.ContactBo;
import com.synnex.mobile.servier.core.contact.dao.ContactDao;
import com.synnex.mobile.servier.core.contact.dto.Contact;
import com.synnex.mobile.servier.core.contact.service.ContactService;
import com.synnex.mobile.servier.core.service.impl.AbstractServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: kerryf
 * Date: 13-8-5
 * To change this template use File | Settings | File Templates.
 */
@Transactional
public class ContactServiceImpl extends AbstractServiceImpl implements ContactService {

    private ContactDao contactDao;

    public void setContactDao(ContactDao contactDao) {
        this.contactDao = contactDao;
    }

    public List<ContactBo> ListContact(String key) {
        List<Contact> recordList = contactDao.ListContact(key);
        return ContactBo.createInstance(recordList);
    }

    public void addContact(ContactBo contactBo) {
        Contact contact = ObjectUtil.copyProperties(contactBo, Contact.class);
        contact.setEntryDate(new Date());

        contactDao.addContact(contact);
    }

    public void editContact(ContactBo recordBo) {
        Contact record = ObjectUtil.copyProperties(recordBo, Contact.class);
        record.setUpdateDate(new Date());

        contactDao.editContact(record);
    }

    public ContactBo getContactBoById(Integer id) {

        Contact contact = contactDao.getContactById(id);
        return   ContactBo.createInstance(contact);
    }

    public void deleteContactById(Integer id) {
        contactDao.  deleteContactById(id);
    }
}
